home *** CD-ROM | disk | FTP | other *** search
Wrap
#!/usr/bin/perl5 # # ppp-in.cgi # # Copyright 1988-1996 Silicon Graphics, Inc. # All rights reserved. # # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.; # the contents of this file may not be disclosed to third parties, copied or # duplicated in any form, in whole or in part, without the prior written # permission of Silicon Graphics, Inc. # # RESTRICTED RIGHTS LEGEND: # Use, duplication or disclosure by the Government is subject to restrictions # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data # and Computer Software clause at DFARS 252.227-7013, and/or in similar or # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished - # rights reserved under the Copyright Laws of the United States. # # $Id: ppp-in.frm,v 1.35 1997/04/17 23:20:39 shotes Exp $ require "/usr/OnRamp/lib/OnRamp.pm"; $conf = "/etc/passwd"; $dummy = "/etc/passwd.temp"; $myname = "ppp-in.cgi"; $title = "Dial-in PPP Accounts"; $js_main = "which = \"none\"; function runSubmit() { // onClick gets processed before onSubmit if(which == \"add\") return runAdd(); if(which == \"edit\") return runEdit(); if(which == \"delete\") return runDelete(); return (true); } function markAdd() { which = \"add\"; } function markEdit() { which = \"edit\"; } function markDelete() { which = \"delete\"; } function markOther() { which = \"none\"; } function runAdd() { form = document.PPPForm; if (!testLogin(form)) return (false); return (true); } function runEdit() { Ctrl = document.PPPForm.chosen; none = true; for(i = 0; i < Ctrl.length; i++) { if (Ctrl.options[i].selected) { none = false; break; } } if(none) { errorBox (Ctrl, \"To edit an existing account, first select an account \\nfrom the list, then click the edit button.\"); return (false); } return (true); } function runDelete() { Ctrl = document.PPPForm.chosen; none = true; for(j = 0; j < Ctrl.length; j++) { if (Ctrl.options[j].selected) { none = false; break; } } if(none) { errorBox (Ctrl, \"To delete an existing account, first select an account \\nfrom the list, then click the delete button.\"); return (false); } return (true); } function testLogin(form) { Ctrl = form.new_account; if (Ctrl.value == \"\") { errorBox (Ctrl, \"The login name is required.\"); return (false); } error = testLoginChars(Ctrl.value); if (error == 1) { errorBox (Ctrl, \"The login name cannot be more \\nthan 8 characters long.\"); return (false); } if (error == 2) { errorBox (Ctrl, \"The login name cannot contain the \" + illegal + \" character.\"); return (false); } if (error == 3) { errorBox (Ctrl, \"The login name cannot contain spaces.\"); return (false); } return (true); } function testLoginChars(word) { if (word.length > 8) return 1; loginChars = \"_-\.{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\"; for(j = 0; j < loginChars.length; j++) { c = loginChars.charAt(j); if (word.indexOf(c, 0) != -1) { illegal = c; return 2; } } for (c = 0; c < word.length; c++) { if (word.charAt(c) == ' ') return 3; } return 0; } function errorBox (Ctrl, ErrorMessage) { alert (ErrorMessage); Ctrl.focus(); return; }"; $js_add = "which = \"none\"; function runSubmit() { // onClick must get processed before onSubmit if(which == \"ok\") return runOK(); return (true); } function markOK() { which = \"ok\"; } function markOther() { which = \"none\"; } function runOK() { form = document.AddForm; // JavaScript can't look at password fields. return (true); } function errorBox (Ctrl, ErrorMessage) { alert (ErrorMessage); Ctrl.focus(); return; }"; $js_edit = "which = \"none\"; function runSubmit() { // onClick gets processed before onSubmit if(which == \"ok\") return runOK(); return (true); } function markOK() { which = \"ok\"; } function markOther() { which = \"none\"; } function runOK() { form = document.EditForm; if (!testLogin(form)) return (false); // JavaScript can't look at password fields. return (true); } function testLogin(form) { Ctrl = form.login; if (Ctrl.value == \"\") { errorBox (Ctrl, \"The login name is required.\"); return (false); } error = testLoginChars(Ctrl.value); if (error == 1) { errorBox (Ctrl, \"The login name cannot be more \\nthan 8 characters long.\"); return (false); } if (error == 2) { errorBox (Ctrl, \"The login name cannot contain the \" + illegal + \" character.\"); return (false); } if (error == 3) { errorBox (Ctrl, \"The login name cannot contain spaces.\"); return (false); } return (true); } function testLoginChars(word) { if (word.length > 8) return 1; loginChars = \"_-\.{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\"; for(j = 0; j < loginChars.length; j++) { c = loginChars.charAt(j); if (word.indexOf(c, 0) != -1) { illegal = c; return 2; } } for (c = 0; c < word.length; c++) { if (word.charAt(c) == ' ') return 3; } return 0; } function errorBox (Ctrl, ErrorMessage) { alert (ErrorMessage); Ctrl.focus(); return; }"; print "Content-type: text/html\n\n"; if ( ! -e "/usr/etc/ppp" ) { &title_block($title); &header_block($title); print "<i>PPP software not installed. Install subsystem </i><b>eoe.sw.ppp</b><i> from the distribution CD.</i>"; exit 0; } &get_fields; &getAccounts; if (%fld) { $fld{'chosen'} =~ /([\w.-]+)/; $fld{'chosen'} = $1; $help = $document_root . $ENV{"SCRIPT_NAME"}; $help =~ s/cgi$/hlp/; exec $help if ($fld{'help'} eq "Help"); if ($fld{'add'}) { &error(2,"Login name required.") if !$fld{'new_account'}; @test = getpwnam($fld{'new_account'}); &error(2,"Account already exists.") if $test[0]; &error(2,"Invalid login name.") if $fld{'new_account'} =~ /$METACHARS/o || $fld{'new_account'} =~ /\s/; $val{'login'} = $fld{'new_account'}; &addAccount; } elsif ($fld{'delete'}) { &error(2,"To delete an existing account, first select an account from list, then click the delete button.") if !$fld{'chosen'}; $message = qq|Click "Ok" to save changes.|; &generic($fld{'chosen'}); } elsif ($fld{'edit'}) { &error(2,"To edit an existing account, first select an account from list, then click the edit button.") if !$fld{'chosen'}; $val{'login'} = $fld{'chosen'}; &editAccount; } elsif ($fld{'doedit'}) { &formValid_doEdit; &doEdit; &getAccounts; &generic; } elsif ($fld{'doit'}) { &tryToDelete; &getAccounts; &generic; } elsif ($fld{'doadd'}) { &formValid_doAdd; &doAdd; &getAccounts; &generic; } else { $message = "Use buttons to submit form."; $val{'new_account'} = $fld{'new_account'}; &generic; } } else { &generic; } sub formValid_doAdd { if (!$fld{'password'}) { &error(0,"You must enter a password."); } if ($fld{'password'} ne $fld{'passcheck'}) { &error(0,"Input passwords not equivalent."); } &error(0,"Invalid login name.") if $fld{'login'} =~ /$METACHARS/o; } sub formValid_doEdit { if ($fld{'password'} ne $fld{'passcheck'}) { &error(1,"Input passwords not equivalent."); } &error(1,"Invalid login name.") if $fld{'login'} =~ /$METACHARS/o; } sub error { &error_block($_[1]); %val = %fld; if ($_[0] == 0) { &addAccount; } elsif ($_[0] == 1) { &editAccount; } else { &generic; } exit 0; } sub doEdit { open(IN,"< $conf"); open(OUT,"> $dummy"); while(<IN>) { @items = split(/:/); if ($items[0] ne $fld{'chosen'}) { print OUT $_; } else { $oldcrypt = $items[1]; } } close(IN); close(OUT); rename($dummy,$conf); if ($fld{'password'}) { &add_password($fld{'login'},$fld{'password'},0,0,$fld{'login'}." ppp","/","/usr/etc/ppp"); } else { open(OUT,">> $conf"); print OUT "$fld{'login'}:$oldcrypt:0:0:$fld{'login'} ppp:/:/usr/etc/ppp\n"; close(OUT); } $message = "Account edited."; } sub editAccount { &js_title_block($title,$js_edit); &header_block("Edit Dial-in PPP Account"); print "<form name=EditForm action=$myname method=post onSubmit=\"return runSubmit()\">"; print qq|<input type=hidden name="chosen" value=$fld{'chosen'}>|; print "<center><table cellpadding=5 width=450>"; print "<tr><th align=left>Login name:</th><th align=left>", &text('login',$val{'login'}, 20),"</th></tr>"; print "<tr><th align=left>Password:</th><th align=left>"; print qq|<input type=password name="password" size=20>|; print "</th></tr>"; print "<tr><th align=left>(Password again):</th><th align=left>"; print qq|<input type=password name="passcheck" size=20>|; print "</th></tr>"; print "</table></center>"; print &js_buttons('doedit','Ok','onClick="markOK()"','onClick="markOther()"'); print "</form></body></html>"; } sub tryToDelete { $account = $fld{'del_name'}; if ($account eq "") { return; } open(IN,"< $conf"); open(OUT,"> $dummy"); while(<IN>) { $line = $_; if ($line =~ /^\s*\#/) { print OUT $line; next; } @items = split(/:/,$line); chop $items[6]; if ($items[6] eq "/usr/etc/ppp" && $items[0] eq $account) { next; } else { print OUT $line; } } close(IN); close(OUT); rename($dummy,$conf); $message = "Account deleted."; } sub doAdd { &add_password($fld{'login'},$fld{'password'},0,0,$fld{'login'}." ppp", "/","/usr/etc/ppp"); $message = "New account added."; } sub addAccount { &js_title_block($title,$js_add); &header_block("Add New Dial-in PPP Account"); print "<form name=AddForm action=$myname method=post onSubmit=\"return runSubmit()\">"; print "<center><table>"; print "<input type=hidden name=login value=$val{'login'}>"; print "<tr><th align=left>Login name:</th><td><tt>", $val{'login'},"</tt></td></tr>"; print "<tr><th align=left>Password:</th><th align=left>"; print qq|<input type=password name="password" size=20>|; print "</th></tr>"; print "<tr><th align=left>(Password again):</th><th align=left>"; print qq|<input type=password name="passcheck" size=20>|; print "</th></tr>"; print "</table></center><br>"; print &js_buttons('doadd','Ok','onClick="markOK()"','onClick="markOther()"'); print "</form></body></html>"; } sub getAccounts { $i = 0; open(IN,"< $conf"); while(<IN>) { $line = $_; if ($line =~ /^\s*\#/) { next; } @items = split(/:/,$line); chop $items[6]; if ($items[6] eq "/usr/etc/ppp") { $name[$i] = $items[0]; $i++; } } $number = $i; close(IN); } sub generic { &js_title_block($title,$js_main); &header_block($title); if (!$number && !$message) { $message = "No existing dial-in PPP accounts."; } print "<i>$message</i>"; print "<form name=PPPForm action=$myname method=post onSubmit=\"return runSubmit()\">"; if ($_[0]) { print qq|<input type=hidden name="del_name" value=$_[0]>|; } if ($number) { print "<h3>Account name:</h3><center>"; print "<table width=400>"; print qq|<tr><td><input type=submit name="add" value="Add New Account" onClick="markAdd()"> </td><td><input name="new_account" value="$val{'new_account'}" size=19></td></tr>|; print "<tr><td>"; print qq|<input type=submit name="edit" value="Edit Selected Account" onClick="markEdit()"></td>|; undef @locList; for ($i=0;$i<$number;$i++) { if ($_[0] ne $name[$i]) { push(@locList,$name[$i]); } } print "<td rowspan=2>"; print &choice_list(*locList,"chosen",20); print "</td></tr>"; print qq|<tr><td><input type=submit name="delete" value="Delete Selected Account" onClick="markDelete()"></td></tr>|; print "</table></center><br>"; } else { print "<center><table width=400>"; print qq|<tr><td><input type=submit name="add" value="Add New Account" onClick="markAdd()"> </td><td><input name="new_account" value="$val{'new_account'}" size=19></td></tr>|; print "<tr><td>"; print "</table>"; } print &js_buttons('doit','Ok','onClick="markOther()"','onClick="markOther()"'); print "</form></body></html>"; }